package com.ludomancy.gamelib;

import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle;

public class TextWidget extends Widget
{
	private String text ="";
	private Font font;
	
	public TextWidget(Widget parent, Rectangle area, String text, Font font)
	{
		super(parent, area);
		setText(text);
		this.font = font;
	}

	public TextWidget(Widget parent, Rectangle area, String text)
	{
		this(parent, area, text, null);
	}
	
	public TextWidget(Widget parent, Rectangle area)
	{
		super(parent, area);
	}

	public void setText(String text)
	{
		this.text = text;
	}

	public void paint(Graphics g)
	{
		if(text != null && text.length() > 0)
		{
			Font old = g.getFont();
			if(font != null && old != font)
			{
				g.setFont(font);
			}
			g.setColor(getTheme().getDefaultTextColor());
			Utils.drawMultiline(g, text, getWidth()-2, 2, 4);
			g.setFont(old);
		}
	}

}
